//
//  ShenPiXiangQingGuanLianKeHuTableViewCell.m
//  JuBoCRM
//
//  Created by iMac on 2024/3/14.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "ShenPiXiangQingGuanLianKeHuTableViewCell.h"
#import "UILabel+YBAttributeTextTapAction.h"
@implementation ShenPiXiangQingGuanLianKeHuTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    

}



- (void)setModel:(AllModel *)model {
    _model = model;
    NSDictionary *dataDic = model.modelInfoDictionary;
    
    if([[dataDic objectForKey:@"customerList"] isKindOfClass:[NSArray class]]){
        NSMutableString *name = [NSMutableString string];
       NSArray *array = [dataDic objectForKey:@"customerList"];
        NSMutableArray *nameArray = [NSMutableArray array];
        for (NSInteger i = 0; i < array.count;i++) {
            if(i < array.count-1){
                [name appendString:[NSString stringWithFormat:@"%@,",GetHandleString(array[i], @"name")]];
            }else{
                [name appendString:GetHandleString(array[i], @"name")];
            }
            [nameArray addObject:GetHandleString(array[i], @"name")];
        }

        NSMutableAttributedString *attributedString2 = [[NSMutableAttributedString alloc]initWithString:name];

        NSMutableParagraphStyle *par = [[NSMutableParagraphStyle alloc]init];

        par.alignment = NSTextAlignmentRight;
        

        NSDictionary *dic1=@{NSParagraphStyleAttributeName : par,

        NSFontAttributeName : [UIFont systemFontOfSize:14],

        NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleNone]

        };

        [attributedString2 setAttributes:dic1 range:NSMakeRange(0, name.length)];

        
        
        _userLabel.text = @"";
        _userLabel.attributedText = attributedString2;
        [_userLabel yb_addAttributeTapActionWithStrings:nameArray tapClicked:^(NSString *string, NSRange range, NSInteger index) {
            NSString *message = [NSString stringWithFormat:@"点击了“%@”字符\nrange: %@\nindex: %ld",string,NSStringFromRange(range),index];
            
            NSLog(@"message:%@",message);
            
            NSDictionary *user = array[index];
            if(_userInfoClickBlock){
                _userInfoClickBlock(GetHandleString(user, @"id"));
            }
       
        }];
        //设置是否有点击效果，默认是YES
        _userLabel.enabledTapEffect = NO;
        
        CGSize baseSize = CGSizeMake(ScreenWidth-100, CGFLOAT_MAX);
        CGSize labelsize  = [name
                            boundingRectWithSize:baseSize
                            options:NSStringDrawingUsesLineFragmentOrigin
                            attributes:dic1
                            context:nil].size;
        
        _userLabel.sd_layout
        .widthIs(ScreenWidth-100)
        .rightSpaceToView(self.contentView, 16)
        .topSpaceToView(self.contentView, 6)
        .heightIs(labelsize.height);
        _userLabel.isAttributedContent = YES;
        
    }else{
        _userLabel.attributedText = nil;
        _userLabel.text = @"";
        
        _userLabel.sd_layout
        .widthIs(ScreenWidth-100)
        .rightSpaceToView(self.contentView, 16)
        .centerYEqualToView(_remindLabel)
        .heightIs(18);
        
    }
 
    
    [self setupAutoHeightWithBottomView:_userLabel bottomMargin:28];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
